const mongoose = require('mongoose');

mongoose.connect('mongodb://localhost/mytest',{useUnifiedTopology: true,useNewUrlParser: true})
  .then(()=> console.log('链接成功'))
  .catch(err => console.log(err,'链接失败'))

const courseSchema = new mongoose.Schema({
  name: String,
  author: String,
  isPublished: Boolean
});

const Course = mongoose.model('Course',courseSchema)
// Course.create({name: 'Javascript',author: 'luo',isPublished: false},
//   (err,res) =>{
//     console.log(err);
//     console.log(res);
//   }
// ) 创建文档
Course.create({name: 'Css',author: 'luo11',isPublished: false})
.then(res=> console.log(res))
.catch(err=> console.log(err))


// 导入数据
// mongoimport -d mytest -c users --file ./user.json